package com.cskaoyan.wordmemorize.controller.admin;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.cskaoyan.wordmemorize.auth.SaAdminCheckPermission;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.converter.VocChapterConverter;
import com.cskaoyan.wordmemorize.dao.entity.VocChapterDO;
import com.cskaoyan.wordmemorize.dto.admin.DeleteChapterOperateDTO;
import com.cskaoyan.wordmemorize.dto.admin.EmployeeDTO;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.VocChapterDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.VocChapterCommand;
import com.cskaoyan.wordmemorize.request.VocChapterPageRequest;
import com.cskaoyan.wordmemorize.service.VocChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/voc")
public class AdminChapterController {

    @Autowired
    VocChapterService vocChapterService;

    // 添加章节(后端-物料管理-章节管理)
    @SaAdminCheckPermission("admin:chapter:add")
    @PostMapping("chapter")
    public Result addChapter(@RequestBody VocChapterCommand command){
        vocChapterService.addChapter(command);
        return Result.ok();
    }

    // 修改章节(后端-物料管理-章节管理)
    @SaAdminCheckPermission("admin:chapter:update")
    @PutMapping("chapter")
    public Result updateChapter(@RequestBody VocChapterCommand command){
        vocChapterService.updateChapter(command);
        return Result.ok();
    }

    // 分页查询章节列表(后端-物料管理-章节管理)
    @SaAdminCheckPermission("admin:chapter:search")
    @GetMapping("chapters/list")
    public Result<PageDTO<VocChapterDTO>> getChapterPage(VocChapterPageRequest pageQuery){
        PageDTO<VocChapterDTO> vocChapterDTOPageDTO = vocChapterService.getChapterPage(pageQuery);
        return Result.ok(vocChapterDTOPageDTO);
    }

    // 删除章节(后端-物料管理-章节管理)
    @SaAdminCheckPermission("admin:chapter:delete")
    @DeleteMapping("chapter/{chapterId}")
    public Result<DeleteChapterOperateDTO> deleteChapter(@PathVariable("chapterId")Long chapterId){
        DeleteChapterOperateDTO deleteChapterOperateDTO = vocChapterService.deleteChapter(chapterId);
        return Result.ok(deleteChapterOperateDTO);
    }

    // 批量删除选中章节(后端-物料管理-章节管理)
    @SaAdminCheckPermission("admin:chapter:batchdelete")
    @DeleteMapping("chapters")
    public Result<List<DeleteChapterOperateDTO>> deleteChapters(@RequestBody BatchDeleteCommand command){
        List<DeleteChapterOperateDTO> deleteChapterOperateDTOS = vocChapterService.deleteChapters(command);
        return Result.ok(deleteChapterOperateDTOS);
    }
}
